cmake_minimum_required(VERSION 3.20)

# =============================================================================
# Project name.
project(
  QtCEFWidget
  VERSION 1.0.0.0 
  DESCRIPTION "Qt Widget with CEF"
  LANGUAGES CXX)

# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# CEF
if (NOT DEFINED CEF_ROOT)
  message(FATAL_ERROR "CEF_ROOT not defined!")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")
find_package(CEF REQUIRED)
PRINT_CEF_CONFIG()

# Qt
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/ui)
find_package(Qt5 COMPONENTS REQUIRED Widgets)

# =============================================================================
# source code
set(HEADER_FILES
  include/QtCEFWidget.h

  src/QtCEFApp.h
  src/QtCEFHandler.h
  )
source_group("${PROJECT_NAME}\\Header Files" FILES ${HEADER_FILES})

set(SRC_FILES
  src/QtCEFWidget.cpp
  src/QtCEFApp.cpp
  src/QtCEFHandler.cpp
  )
source_group("${PROJECT_NAME}\\Source Files" FILES ${SRC_FILES})

# =============================================================================
# adding a library
add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SRC_FILES})

# =============================================================================
# 编译选项
target_compile_options(${PROJECT_NAME} PRIVATE 
  /wd"4100"   # 忽略编译警告：未引用的形参，CEF库中有大量的该警告
  /wd"4324"      # 忽略编译警告：由于对齐说明符，结构被填充
  )
if (OS_WINDOWS)
  target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN32_WINNT=0x0601)
endif()

# use CEF
target_include_directories(${PROJECT_NAME} PRIVATE ${CEF_ROOT})
target_link_directories(${PROJECT_NAME} PRIVATE ${CEF_ROOT})
target_link_directories(${PROJECT_NAME} PRIVATE ${CEF_ROOT}/build/libcef_dll_wrapper/$<CONFIG>/)
target_link_libraries(${PROJECT_NAME} PRIVATE libcef_dll_wrapper libcef)

# use Qt
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets)